﻿using System;
using Com.PhilChuang.Pmvp.Model.Services;
using Com.PhilChuang.Pmvp.Model.Services.Impl;
using Com.PhilChuang.Pmvp.Ui.Presenters;
using Com.PhilChuang.Pmvp.Ui.Views;
using Com.PhilChuang.Pmvp.Ui.Views.Impl.Pages;
using Com.PhilChuang.Pmvp.Ui.Views.Impl.ViewFacades;
using Com.PhilChuang.Utils;
using Com.PhilChuang.Utils.Mobile;

namespace Com.PhilChuang.Pmvp.Utils
{
	public static class PmvpUtilsWp7ServiceLocator
	{
		public static void AddServices (IServiceLocator locator)
		{
			// services
			locator.AddMapping (typeof (ITrialModeService), typeof (TrialModeService), true);
			
			// views
			locator.AddMapping (typeof (IAboutView), typeof (AboutViewFacade), false);
			locator.AddMapping (typeof (IReportBugView), typeof (SendFeedbackViewFacade), false);
			locator.AddMapping (typeof (ISendFeedbackView), typeof (SendFeedbackViewFacade), false);
		}

		public static void AddNavigationHelperMappings (NavigationHelper helper)
		{
			helper.AddMapping (new NavigationHelperMapping (
			                   	typeof (AboutPage),
			                   	"/PmvpUtilsWp7;component/Ui/Views/Impl/Pages/AboutPage.xaml",
			                   	page => new AboutPresenter (new AboutViewFacade ((AboutPage) page))));
			helper.AddMapping (new NavigationHelperMapping (
			                   	typeof (SendFeedbackPage),
			                   	"/PmvpUtilsWp7;component/Ui/Views/Impl/Pages/SendFeedbackPage.xaml",
			                   	page => {
			                   		var vf = new SendFeedbackViewFacade ((SendFeedbackPage) page);
			                   		if (vf.IsBugReport)
			                   			new ReportBugPresenter (vf);
			                   		else
			                   			new SendFeedbackPresenter (vf);
			                   	}));
		}
	}
}
